<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>首页</title>
    <link href="css/mui.min.css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="css/iconfont.css"/>
	<link rel="stylesheet" type="text/css" href="css/lcs-font.css"/>
	<style type="text/css">
		
	</style>
	</style>
</head>
<body>
	
	<nav class="mui-bar mui-bar-tab">
		<a class="mui-tab-item mui-active" href="workbench/main.html">
			<span class="mui-icon iconfont icon-shebeizhuangtai"></span>
			<span class="mui-tab-label">工作台</span>
		</a>
		<a class="mui-tab-item" href="business/main.html">
			<span class="mui-icon iconfont icon-shujukanban"></span>
			<span class="mui-tab-label">营业分析</span>
		</a>
		<a class="mui-tab-item" href="">
			<span class="mui-icon iconfont icon-icon_tianjia"></span>
			<span class="mui-tab-label">收银记账</span>
		</a>
		<a class="mui-tab-item" href="inventory/main.html">
			<span class="mui-icon iconfont icon-icon_baocun"></span>
			<span class="mui-tab-label">库存管理</span>
		</a>
		<a class="mui-tab-item" href="personal/personal.html">
			<span class="mui-icon iconfont icon-icon_zhanghao"></span>
			<span class="mui-tab-label">我的</span>
		</a>
	</nav>
	<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/mui.min.js"></script>
	<script src="js/req.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/muishow.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript" charset="utf-8">
			
			var vurl = "";//版本路径
			var index = 0;
			var subpages = ["workbench/main.html",
				"business/main.html",
				"",
				"inventory/main.html",
				"personal/personal.html"];
			
			
			mui.init();
			var activeTab = subpages[index];
			
			mui.plusReady(function () {
					    var self = plus.webview.currentWebview();
							for (var i = 0; i < subpages.length; i++) {
								var sub = plus.webview.create(
								subpages[i], subpages[i], {
									top: '0px',
									bottom: '50px'
								});
								if(i > index){
									sub.hide();
								}
								self.append(sub);
								
							}
		            		var backButtonPress = 0;
							mui.back = function(event) {
								backButtonPress++;
								if (backButtonPress > 1) {
									plus.runtime.quit();
								} else {
									plus.nativeUI.toast('再按一次退出应用');
								}
								setTimeout(function() {
									backButtonPress = 0;
								}, 1000);
								return false;
							};
							//checkVersion();
							
					});
	
			
			mui('.mui-bar-tab').on('tap', 'a', function (){
				var targetTab = this.getAttribute('href');
				if(activeTab == targetTab){
					return;
				}
				if(mui.os.plus && "" != targetTab){
					plus.webview.show(targetTab);
					plus.webview.hide(activeTab);
					activeTab = targetTab;
				} else if("" != targetTab){
					createIframe('.mui-content', {
						url: targetTab,
						style: {
							top: '0px',
							bottom: '50px'
						}
					})
				}else{
					mui.openWindow({
                        url: "workbench/cashier.html",
                        id: "cashier"
                	});
				}
			});
			function createIframe(el,opt) {
				var elContainer = document.querySelector('mui-content');
				var wrapper = document.querySelector('.mui-iframe-wrapper');
				if(!wrapper){
					wrapper = document.createElement('div');
					wrapper.className = 'mui-iframe-wrapper';
					for (var i in opt.style) {
						wrapper[i] = opt.style[i];
					}
				}	
				var iframe = document.createElement('iframe');
				iframe.src = opt.url;
				iframe.id = opt.id || opt.url;
				iframe.name = opt.id;
				wrapper.appendChild(iframe);
				elContainer.appendChild(wrapper);
			}
			window.onload = function(){
				checkVersion();
			}
			
			//检查版本更新
			
			function checkVersion(){
				var data = {
					url:"/api/version/check",
					data:{
						access_token:acctoken(),
					}
				}
				ajax(data,function(res){
					console.log("版本",res);
					if(res.data.serial_number > parseFloat(version)){
					var list = {vurl: res.data.path_url||"",content:res.data.content};
					mui.openWindow({
					    url: 'version-page.html?vurl='+res.data.path_url+'&content='+res.data.content, 
					    id: 'version-page',
					    extras: list,
					 });
					/*plus.webview.open( 
						'version-page.html', 
						'version-page',
					);*/
					
					}else{
						console.log("最新版");
					}
				})
				
				
			}
			
	</script>
</body>
</html>
